package cn.com.inossem.utils.view;

import android.app.DatePickerDialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.DatePicker;
import android.widget.LinearLayout;
import android.widget.NumberPicker;

/**
 * Created by Mickey.Li
 * Time 2017-12-19 下午 4:11
 */

public class MonPickerDialog extends DatePickerDialog {
	public MonPickerDialog(Context context, int theme, int year, int monthOfYear, int dayOfMonth, OnDateSetListener listener) {
		super(context, theme, listener, year, monthOfYear, dayOfMonth);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		LinearLayout mSpinners = (LinearLayout) findViewById(getContext().getResources().getIdentifier("android:id/pickers", null, null));
		if (mSpinners != null) {
			NumberPicker mYearSpinner = (NumberPicker) findViewById(getContext().getResources().getIdentifier("android:id/year", null, null));
			NumberPicker mMonthSpinner = (NumberPicker) findViewById(getContext().getResources().getIdentifier("android:id/month", null, null));
			mSpinners.removeAllViews();
			//如果要隐藏年，月，日中的某一项取消其addView就好了
			if (mYearSpinner != null) {
				mSpinners.addView(mYearSpinner);
			}
			if (mMonthSpinner != null) {
				mSpinners.addView(mMonthSpinner);
			}
		}
	}

	@Override
	public void onDateChanged(DatePicker view, int year, int month, int day) {
		super.onDateChanged(view, year, month, day);
		this.setTitle(year + "年");
	}
}
